package com.bjhb.wuranyuan.web.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.bjhb.wuranyuan.dao.QysbxxMapper;
import com.bjhb.wuranyuan.dao.QyxxMapper;
import com.bjhb.wuranyuan.pojo.Qysbxx;
import com.bjhb.wuranyuan.pojo.Qyxx;

@Controller
public class QysbxxAction {

	@Resource
	private QysbxxMapper qysbxxMapper;
	@Resource
	private QyxxMapper qyxxMapper;

	@RequestMapping("/qysbxx.htm")
	public String list(HttpServletRequest request,
			@RequestParam("qydm") String qydm) {
		Qyxx qyxx = qyxxMapper.selectByQydm(qydm);
		List<Qysbxx> list = qysbxxMapper.selectByQydm(qydm);
		request.setAttribute("list", list);
		request.setAttribute("qyxx", qyxx);
		return "qysbxx/qysbxx";
	}

	@RequestMapping("/qysbxx/edit.htm")
	public String edit(HttpServletRequest request, String sbid, String qydm) {
		Qysbxx sbxx = qysbxxMapper.selectBySbid(sbid);
		Qyxx qyxx = qyxxMapper.selectByQydm(qydm);
		request.setAttribute("qyxx", qyxx);
		request.setAttribute("qysbxx", sbxx);
		return "qysbxx/qysbxx_edit";
	}

	@RequestMapping("/qysbxx/update.htm")
	public String update(HttpServletRequest request, Qysbxx qysbxx) {
		qysbxxMapper.update(qysbxx);
		request.setAttribute("flg", "true");
		return "qysbxx/qysbxx_edit";
	}

	@RequestMapping("/qysbxx/add.htm")
	public String add(HttpServletRequest request, Qysbxx qysbxx) {
		qysbxx.setModid("01");
		qysbxx.setDsjkms(4);
		qysbxx.setDsjktxyc(0);
		qysbxx.setCbtdxx("00000000");
		qysbxx.setTxsblx("GPRS");
		qysbxx.setWorkType("1");
		qysbxx.setDayBegin("0");
		qysbxx.setDayEnd("23");

		qysbxxMapper.insert(qysbxx);
		request.setAttribute("flg", "true");
		return "qysbxx/qysbxx_edit";
	}

	@RequestMapping("qysbxx/delete.htm")
	public void delete(HttpServletResponse resp, String[] sbids, String qydm) {
		if (sbids != null) {
			for (String sbid : sbids) {
				qysbxxMapper.delete(sbid);
			}
		}
		try {
			resp.sendRedirect("../qysbxx.htm?qydm=" + qydm);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
